﻿/* 
   Copyright 2011 LUCA Studios LLC & John Evans

   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at

     http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.
*/

namespace LUCAStudios.Silverlight.Controls
{
    using System.Collections.ObjectModel;

    /// <summary>
    /// A lightweight non-persistent logging helper for runtime debugging
    /// </summary>
    public static class Logger
    {
        /// <summary>
        /// Clears the log entry list.
        /// </summary>
        public static void Clear()
        {
            Entries.Clear();
        }

        /// <summary>
        /// Adds a log entry to the end of the list
        /// </summary>
        /// <param name="source">Optional string indicating the source of the entry</param>
        /// <param name="logEntry">The log entry.</param>
        public static void AddEntry(string source, string logEntry)
        {
            Entries.Add(source == string.Empty
                            ? string.Format("{0}", logEntry)
                            : string.Format("({0}) {1}", source, logEntry));
        }

        /// <summary>
        /// Inserts a log entry at the beginning of the list
        /// </summary>
        /// <param name="source">Optional string indicating the source of the entry</param>
        /// <param name="logEntry">The log entry.</param>
        public static void InsertEntry(string source, string logEntry)
        {
            Entries.Insert(0,
                           source == string.Empty
                               ? string.Format("{0}", logEntry)
                               : string.Format("({0}) {1}", source, logEntry));
        }

        private static readonly ObservableCollection<string> Logentries = new ObservableCollection<string>();
        /// <summary>
        /// Bindable collection of log entries
        /// </summary>
        public static ObservableCollection<string> Entries
        {
            get { return Logentries; }

        }
    }
}
